package cn.stylefeng.guns.modular.yingbao.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.yingbao.entity.SysProtocol;
import cn.stylefeng.guns.modular.yingbao.model.params.SysProtocolParam;
import cn.stylefeng.guns.modular.yingbao.service.SysProtocolService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 协议设置控制器
 *
 * @author jj
 * @Date 2020-01-10 14:45:08
 */
@CrossOrigin
@Controller
@RequestMapping("/sysProtocol")
public class SysProtocolController extends BaseController {

    private String PREFIX = "/sysProtocol";

    @Autowired
    private SysProtocolService sysProtocolService;

    /**
     * 跳转到主页面
     *
     * @author jj
     * @Date 2020-01-10
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/sysProtocol.html";
    }

    /**
     * 新增页面
     *
     * @author jj
     * @Date 2020-01-10
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/sysProtocol_add.html";
    }

    /**
     * 编辑页面
     *
     * @author jj
     * @Date 2020-01-10
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/sysProtocol_edit.html";
    }

    /**
     * 新增接口
     *
     * @author jj
     * @Date 2020-01-10
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(SysProtocolParam sysProtocolParam) {
        this.sysProtocolService.add(sysProtocolParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author jj
     * @Date 2020-01-10
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(SysProtocolParam sysProtocolParam) {
        this.sysProtocolService.update(sysProtocolParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author jj
     * @Date 2020-01-10
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(SysProtocolParam sysProtocolParam) {
        this.sysProtocolService.delete(sysProtocolParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author jj
     * @Date 2020-01-10
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(SysProtocolParam sysProtocolParam) {
        SysProtocol detail = this.sysProtocolService.getById(sysProtocolParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author jj
     * @Date 2020-01-10
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(SysProtocolParam sysProtocolParam) {
        return this.sysProtocolService.findPageBySpec(sysProtocolParam);
    }

    @PostMapping("queryByType")
    @ResponseBody
    public ResponseData queyrByTypr(Integer type){
        return sysProtocolService.queryByType(type);
    }

}


